<?php


namespace catchAdmin\project\request;


use think\exception\ValidateException;
use think\Validate;

class NodeRequest extends Validate
{
    protected $rule = [
        'node_name|节点名称' => 'require',
        'node_id|节点id' => 'require',
        'is_whole_hospital|是否全院' => [
            'in:0,1'
        ],
        'apply_dept|适用部门' => [
            'checkApply'

        ],
        'project_id|问卷编码' => ['require'],


    ];

    // 自定义验证规则
    protected function checkApply($value, $rule, $data = []): bool
    {
        if ($data["is_whole_hospital"] === 0 && empty($data["apply_dept"])) {
            throw new ValidateException("适用部门必须填写");
        }
        return true;
    }


}